<?php
namespace Admin\Controller;
/**
 * 短信操作控制器
 */
class MsgController extends AdminController {

    /**
     * 后台首页
     */
    public function index(){
        $dao=M('MobileRemessage');
        if(isset($_GET['id'])&&isset($_GET['status'])){
            $arr=array('status'=>I('status'));
            $dao->where(array('id'=>I('id')))->save($arr);
        }
        $this->meta_title = '已接收短消息';
        $map=array();
        $list=$this->lists($dao,$map,'id DESC','*');
        $this->assign('list',$list);
        $this->display();
    }

    public function sendmsg(){
        if(IS_POST){
            $mobile=I('mobile');
            $msgtext=I('msgtext');
            if(empty($mobile)||empty($msgtext)){
                $this->error('发送的手机号码或短信内容不能为空');
            }
            $mobile=explode("\n", $mobile);
            $err='';
            foreach ($mobile as $v) {
                if (!is_numeric((int)$v)) {
                    $err.="\n".$v;
                    continue;
                }
                if(!preg_match('#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#', (int)$v)){
                    $err.="\n".$v;
                }else{
                    send_mobile_message($v,$msgtext);
                }
            }
            if($err!=''){
                $this->assign('err',$err);
            }else{
                $this->success('发送成功！', U('msglist'));
                exit;
            }
        }
        $this->meta_title = '发送短消息';
        $this->display();
    }
    
    public function msglist(){
        $this->meta_title = '已发送短消息';
        $dao=M('MobileMessage');
        $map=array();
        $list=$this->lists($dao,$map,'id DESC','*');
        $this->assign('list',$list);
        $this->display();
    }
}



